import threading,time
def my_counter():
    i = 0
    for _ in range(1000000):
        i += 1
    return True
def main1():
    thread_ary = {}
    start_time = time.time()
    for tid in range(2):
        t = threading.Thread(target=my_counter)
        t.start()
        t.join()
    print('单线程总耗时',time.time()-start_time)
def main2():

    thread_ary = {}
    start_time = time.time()

    for tid in range(10):
        t = threading.Thread(target=my_counter)
        t.start()
        thread_ary[tid] = t
    for i in range(2):
        thread_ary[i].join()
    print('并发执行总耗时',time.time()-start_time)

if __name__ == "__main__":
    main1()
    main2()



def my_counter2():
    i = 0
    for _ in range(10000000):
        i += 1
    return True
start_time = time.time()
my_counter2()
end_time = time.time()
print('Ex',end_time-start_time)

